class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        // write code here
        if (head == nullptr)
            return nullptr;
        if (head->val == val)
            return head->next;
        ListNode* node = head;
        while (node && node->next)
        {
            if (node->next->val == val)
                break;
            node = node->next;
        }
        node->next = node->next->next;
        return head;
    }
};